package cn.stylefeng.guns.topspeedCarRace;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.compress.utils.Sets;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @Description TODO
 * @Author xiesm
 * @Date 2023/3/27 17:10
 **/
public class Test0327 {
    public static void main(String[] args) {
        String path = "D:\\file\\0330\\salog107-2023-03-29.log";
//        test1(path);
//        path = "D:\\file\\0330\\salog195-2023-03-29.log";
//        test1(path);
//        path = "D:\\file\\0330\\salog226-2023-03-29.log";
//        test1(path);
//        path = "D:\\file\\0330\\orders107-2023-03-29.log";
//        test2(path);
//        path = "D:\\file\\0330\\orders195-2023-03-29.log";
//        test2(path);
//        path = "D:\\file\\0330\\orders226-2023-03-29.log";
//        test2(path);

        path = "D:\\file\\0330\\日志req.log";
        String path2 = "D:\\file\\0330\\订单req.log";
        test3(path, path2);
    }

    //比较2份文件，将漏的订单写入文件
    public static void test3(String path1, String path2) {
        List<String> list1 = FileUtil.readLines(path1, Charset.defaultCharset());
        List<String> list2 = FileUtil.readLines(path2, Charset.defaultCharset());
        Set<String> set1 = Sets.newHashSet();
        Set<String> set2 = Sets.newHashSet();
        for (int i = 0; i < list1.size(); i++) {
            String s = list1.get(i);
            set1.add(s);
        }
        for (int i = 0; i < list2.size(); i++) {
            if (set1.add(list2.get(i))) {
                set2.add(list2.get(i));
            }
        }
        FileUtil.writeLines(set2, "D:\\file\\0330\\差异req.log", Charset.defaultCharset(), true);
    }

    //将订单收费订单写入文件
    public static void test2(String path) {
        List<String> list = FileUtil.readLines(path, Charset.defaultCharset());
        List<String> list2 = Lists.newArrayList();
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            JSONObject jsonObject = JSONObject.parseObject(s);
            if (Objects.equals("1", jsonObject.getString("flag"))) {
                list2.add(jsonObject.getString("requestId"));
            }
        }
        FileUtil.writeLines(list2, "D:\\file\\0330\\订单req.log", Charset.defaultCharset(), true);
    }

    //将订单收费订单写入文件
//    public static void test3(String path) {
//        List<String> list = FileUtil.readLines(path, Charset.defaultCharset());
//        List<String> list2 = Lists.newArrayList();
//        for (int i = 0; i < list.size(); i++) {
//            String s = list.get(i);
//            JSONObject jsonObject = JSONObject.parseObject(s);
//            if (Objects.equals("1", jsonObject.getString("flag"))) {
//                list2.add(jsonObject.getString("requestId"));
//            }
//        }
//        FileUtil.writeLines(list2, "D:\\file\\0327\\订单req.log", Charset.defaultCharset(), true);
//    }

    //将日志收费订单写入文件
    public static void test1(String path) {
        List<String> list = FileUtil.readLines(path, Charset.defaultCharset());
        List<String> list2 = Lists.newArrayList();
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            String[] ss = s.split("\\|\\|");
            String flag = ss[13];
            if (Objects.equals(flag, "1")) {
                list2.add(ss[8]);
            }
        }
        FileUtil.writeLines(list2, "D:\\file\\0330\\日志req.log", Charset.defaultCharset(), true);
    }
}
